package com.cloudeggtech.granite.chat.model;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.cloudeggtech.granite.sdk.GIMCallback;
import com.cloudeggtech.granite.sdk.GIMManager;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by david on 17/10/27.
 */

public class UserInfo {
    private String mobile;
    private String password;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            EventBus.getDefault().post(new LoginFailedEvent(null));
        }
    };

    public UserInfo() {
    }

    public UserInfo(String mobile, String password) {
        this.mobile = mobile;
        this.password = password;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void login() {
        GIMManager.getInstance().login(mobile, password, new GIMCallback() {
            @Override
            public void success() {
                EventBus.getDefault().post(new LoginSuccessEvent());
            }

            @Override
            public void failure(Throwable t) {
                EventBus.getDefault().post(new LoginFailedEvent(t));
            }
        });
    }

    public static final class LoginSuccessEvent {

    }

    public static final class LoginFailedEvent extends FailedEvent {

        protected LoginFailedEvent(Throwable t) {
            super(t);
        }
    }
}
